Repository navigation
[Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns - #12007
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
What Problem Does This PR Solve?
NumericFunction (backing the Zeta SQL ABS, ROUND, CEIL, CEILING, FLOOR, TRUNC, TRUNCATE, and SIGN functions) dispatches on the runtime Java type of its argument with instanceof chains and a switch on the class simple name. Byte/Short (i.e. TINYINT/SMALLINT) were missing from most of these branches:
ABS/SIGNthrewUnsupported arg type java.lang.Byte/ShortforTINYINT/SMALLINTcolumns, even thoughABS's own doc comment namesTINYINT/SMALLINTas supported.- The shared
round()helper had noBYTEcase, soROUND/CEIL/FLOOR/TRUNCon aTINYINTcolumn silently returned the value unrounded (no exception, no log). SIGNonBigDecimalwent throughdoubleValue(), so a magnitude belowDouble.MIN_VALUEunderflowed to0.0and lost its sign.
This PR closes #11935 by adding Byte/Short branches to abs()/sign(), adding a BYTE case (with an overflow-checked narrowing) to the shared round()/convertTo() helpers, adding a default branch to round()'s switch so an unhandled type now throws instead of silently passing through, and switching SIGN's BigDecimal branch to BigDecimal.signum().
Important duplicate-scope note before the rest of this review: #11935 is already being fixed by the open PR #11937 ("Handle TINYINT and SMALLINT in Zeta SQL numeric functions", opened 2026-08-22, i.e. 8 days before this PR), which touches the exact same methods in the exact same file and is already approved by two reviewers (@goutamadwant and myself, @DanielLeens), pending only its stacked dependency #11927 landing first. See Issue 1 below — this materially affects the merge recommendation.
1. Code Change Review
1.1 Core Logic Analysis
abs(): the newByte/Shortbranches correctly guardByte.MIN_VALUE/Short.MIN_VALUE(whose absolute value doesn't fit the same type) before callingMath.abs, mirroring the existing pattern. Correct.sign(): foldingByte/Shortinto the existingIntegerbranch viaInteger.signum(v1.intValue())is correct — aByte/Shortvalue always fits in anintwithout precision loss, sosignumis unaffected by the widening.sign()onBigDecimal: switching fromv1.doubleValue()(sign-testing afterdoubleconversion) to((BigDecimal) v1).signum()is a real correctness fix, not just aTINYINT/SMALLINTaddition — the previous code underflowed any magnitude belowDouble.MIN_VALUEto0.0. Covered by the new1E-400test.round()'s newBYTEcase follows the exact same negative-scale-only rounding path already used forINTEGER/SHORT/LONG, and routes the narrowed result throughconvertTo("BYTE", ...), which now range-checks againstByte.MIN_VALUE/Byte.MAX_VALUEbefore narrowing. Verified:round(Byte.MAX_VALUE, -1)(127 → 130) now throws instead of wrapping — good, this closes a real overflow-wrap hole for the newly-added type.- New
default: throwbranch onround()'s switch: previously, an argument type matching none of thecaselabels fell straight through the switch with no side effect, and the method returned the input unrounded with no exception, no log. This is a genuine bug fix (confirmed viagit diffagainstorigin/dev: nodefaultexisted before). The newdefaultis exercised by the addedBigIntegertest.
1.2 Compatibility Impact
Partially incompatible — and not fully documented (see Issue 3). Two independent behavior changes ship in this diff:
ROUND/CEIL/FLOOR/TRUNCon aTINYINTcolumn previously returned the value unrounded with no error; it is now correctly rounded, and now throws if the rounded value overflowsTINYINT. A job that happened to rely on the old (buggy) unrounded pass-through will see different output after upgrading.ABS/SIGNonTINYINT/SMALLINTpreviously always threw; they now succeed and return a value. Any existing job with a workaround (e.g. casting toINTfirst) is unaffected but now redundant.- Any numeric type not covered by
round()'s switch (previously silently passed through) now throws aTransformException.
Per this repo's own CLAUDE.md doc rule ("Any incompatible change MUST ... be documented in docs/en/introduction/concepts/incompatible-changes.md"), and per the precedent already set by #11937 for this exact same change (see its diff to that file), this PR should add an entry there (and in the docs/zh counterpart) but does not. See Issue 3.
1.3 Performance / Side-Effect Analysis
No concerns. The added branches are a handful of instanceof checks and a new switch case on the hot path of scalar SQL function evaluation — negligible CPU cost, no new allocations beyond what the existing code already does, no locks/retries/IO involved.
1.4 Error Handling and Logging
Consistent with the existing style in this class: TransformException with CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION and a message naming the function, the value, and the target type. No secrets logged, appropriate for a transform-evaluation failure (surfaces to the user via the SQL engine's expression-evaluation wrapper). No exceptions are swallowed.
One incompleteness rather than an error-handling defect: the new overflow guard in convertTo() is added only for the new "BYTE" case. The pre-existing "SHORT" case (column.shortValue()) still narrows without a range check, so the identical overflow-wrap bug that this PR fixes for TINYINT remains live for SMALLINT immediately next to it. See Issue 2.
2. Code Quality Assessment
2.1 Coding Standards
Clean, minimal, consistent with the surrounding code's existing conventions (same instanceof ordering style, same exception message format, same switch-case style). No wildcard imports, no stray changes outside the intended scope.
2.2 Test Coverage and Test Stability
Good coverage for what's in scope: NumericFunctionTest adds unit cases for Byte/Short abs()/sign(), the Byte.MIN_VALUE/Short.MIN_VALUE abs() overflow exceptions, Byte rounding for ROUND/CEIL/FLOOR/TRUNC, the Byte.MAX_VALUE round-overflow exception, the BigInteger unsupported-type exception (exercising the new default branch), and the BigDecimal("1E-400") sign-underflow fix. SQLNumericFunctionsTest adds an end-to-end SQLTransform case exercising ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC against real TINYINT/SMALLINT columns, which is the right level to also prove the type-dispatch path (ZetaSQLType.getFunctionType) resolves to the same branches.
Stability rating: Stable. All new tests are deterministic pure-function/unit-level assertions — no Thread.sleep, no timing dependencies, no shared mutable state, no floating-point-without-delta comparisons (the one BigDecimal assertion is assertEquals on decimal values, which is exact).
Gap: no test for SMALLINT round-overflow (e.g. CEIL(Short.MAX_VALUE, -1)), which — per Issue 2 — would currently fail to throw and instead return a silently wrapped negative value.
2.3 Documentation Updates
docs/en/transforms/sql-functions.md doesn't strictly need a content change here — as PR #11937 established while fixing the same issue, that page's ROUND overflow note is already written generically for "an integral type" and its ABS section already names TINYINT/SMALLINT. However, docs/en/introduction/concepts/incompatible-changes.md (and docs/zh) is not updated, and per Section 1.2 above, it should be. See Issue 3.
3. Architectural Soundness
3.1 Elegance of the Solution
The approach (mirror the existing Integer/Long handling for Byte/Short) is the right shape and reuses the existing round()/convertTo() structure rather than introducing a parallel code path. Appropriately minimal for the stated scope.
3.2 Maintainability
Fine on its own terms, but see Issue 1: landing this independently of #11937/#11927 would leave the file in an inconsistent state where TINYINT is overflow-guarded through round() but the otherwise-identical SMALLINT path is not — future maintainers would reasonably expect symmetric handling given how closely the two case blocks sit.
3.3 Extensibility
No concerns beyond what's noted above; the default branch added to round()'s switch is good practice for extensibility (any future numeric type added to the type system will now fail loudly here instead of being silently mishandled).
3.4 Historical-Version Compatibility
See Section 1.2 — this is a behavior change for jobs currently relying on the (buggy) old TINYINT pass-through or the old ABS/SIGN rejection, and it is not yet documented in incompatible-changes.md as the project's own convention requires.
4. Issue Summary
Issue 1 — Duplicate/overlapping scope with already-approved PR #11937
- Location: whole PR vs.
apache/seatunnel#11937(stacked on#11927) - Problem: Both PRs close the same issue (#11935) by editing the same methods in the same file (
NumericFunction.java:abs(),round(),convertTo(),sign()). #11937 was opened 8 days earlier and already carries two approvals (@goutamadwant,@DanielLeens), and is strictly more complete: (a) it stacks on#11927's sharedcheckIntegralRangehelper, which range-checksBYTE,SHORT,INTEGER, andLONGuniformly — this PR only range-checks the newBYTEcase (see Issue 2); (b) it fixes the pre-existingt.toUpperCase()/valueType.toUpperCase()default-locale dispatch bug (breaks under a Turkish JVM locale) via a follow-up commit pinning toLocale.ROOT— this PR inherits the same locale-dependent switch unchanged; (c) it documents the breaking-change behavior indocs/en(zh)/introduction/concepts/incompatible-changes.md— this PR does not (Issue 3). - Potential risk: merging both would produce a direct file-level conflict on the same switch/
instanceofchains; reviewer and maintainer time gets split across two competing fixes for one bug. - Best improvement: the author should check with the maintainers /
@SEPURI-SAI-KRISHNAbefore proceeding — either close this PR in favor of #11937 (once its dependency #11927 merges), or, if there's a concrete reason to prefer this PR's approach, explicitly call that out and close #11937 instead. Either way, only one should move forward. - Severity: High
- Raised by another reviewer: No (new finding from this review; I am also a reviewer on #11937, disclosed above).
Issue 2 — SMALLINT overflow-wrap left unguarded
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java,convertTo(),case "SHORT":(pre-existing line, unchanged by this diff, a few lines below the newcase "BYTE":block) - Problem: The new
"BYTE"case inconvertTo()range-checks againstByte.MIN_VALUE/Byte.MAX_VALUEbefore narrowing, throwing on overflow. The adjacent, pre-existing"SHORT"case still does an uncheckedcolumn.shortValue(). Since this PR's own stated goal isTINYINT+SMALLINTsupport, and the negative-scale rounding path (round()) is shared by both types,CEIL(Short.MAX_VALUE /* SMALLINT */, -1)(32767 → 32770) will still silently wrap to-32766instead of throwing — the exact class of bug this PR fixes forTINYINT, left in place forSMALLINTone case-label away. - Potential risk: a job rounding a
SMALLINTcolumn near its max/min with a negative scale silently produces a wrong (and sign-flipped) result instead of failing loudly — worse than theTINYINTcase this PR is fixing, since it now looks "fixed" for small integers in general. - Best improvement: add the same range check to the
"SHORT"case (this is exactly what#11927's sharedcheckIntegralRangehelper already does acrossBYTE/SHORT/INTEGER/LONGuniformly). - Severity: Medium
- Raised by another reviewer: No.
Issue 3 — Missing incompatible-changes.md entry for the breaking behavior change
- Location:
docs/en/introduction/concepts/incompatible-changes.md,docs/zh/introduction/concepts/incompatible-changes.md(not touched by this PR) - Problem: Per Section 1.2, this PR changes observable behavior for existing jobs (silent
TINYINTpass-through → rounded-or-throws;ABS/SIGNrejection → success). The project's ownCLAUDE.mdrequires such changes to be documented here, and the parallel PR #11937 already set the precedent by adding a detailed entry (with before/after tables and a migration guide) for this identical change. - Potential risk: users upgrading won't know why a previously-silent
TINYINTROUNDnow changes its output, or why a previously-failingABS/SIGNonTINYINT/SMALLINTnow succeeds. - Best improvement: add an entry mirroring #11937's (adjusted for this PR's actual diff, e.g. it does not need the
Locale.ROOTmention since that fix isn't included here). - Severity: Medium
- Raised by another reviewer: No.
5. Merge Recommendation
Not recommended for merge, primarily due to Issue 1: this duplicates the scope of the already twice-approved PR #11937, and merging this PR as-is would either conflict with #11937 at the file level or ship a materially less complete fix (missing the SMALLINT overflow guard from Issue 2, missing the locale-independence fix, missing the required incompatible-changes.md documentation from Issue 3) for the exact same underlying issue #11935. I'd suggest the author coordinate with the maintainers and with @SEPURI-SAI-KRISHNA on #11937 before either PR proceeds further.
Separately, CI on this PR's head (034a3f47) shows one failing job — unit-test (8, windows-latest) — but it fails in FileCollectReaderBehaviorTest.rediscoversFileAfterInactiveCursorClosed inside seatunnel-edge-agent-connector, a module this PR does not touch, with an AssertionFailedError: expected: <1> but was: <0> from what looks like a timing-sensitive file-watch test; this is unrelated to this PR's diff. All other jobs (including unit-test on the other three OS/JDK combinations, and the full connector/JDBC/engine IT matrix) passed. The PR is also behind_by=10 commits from dev (diverged, ahead_by=1); a rebase/sync is worth doing but is not itself a blocker given the above.
SEZ9
left a comment
There was a problem hiding this comment.
Thanks for working on this. I reviewed the latest head 034a3f474cbd.
What this PR fixes
- User pain: Zeta SQL numeric functions mishandle TINYINT/SMALLINT columns (#11935) — ABS silently widens Byte/Short, ROUND/CEIL/FLOOR/TRUNC return TINYINT inputs unchanged instead of rounding, and SIGN rejects small integer types while losing the sign of tiny DECIMAL values via lossy double conversion.
- Fix approach: Adds Byte/Short branches to abs() with MIN_VALUE guards, adds a "BYTE" case to the shared round helper's type dispatch plus a BYTE overflow check in convertTo(), replaces the previously-silent pass-through with a default-throw for unsupported Number types, widens sign() to accept Byte/Short, and switches DECIMAL sign to BigDecimal.signum().
- One-line summary: The TINYINT path and SIGN/ABS fixes are correct and well-tested, but the fix is asymmetric — SMALLINT/INTEGER rounding overflow still wraps silently in convertTo(), the new default-throw in the shared helper is a behavior break for previously pass-through Number types, the overflow error message hardcodes ROUND for all callers of the shared helper, and ZetaSQLType is not updated so the declared output type may not match the new Byte runtime values.
Findings
Issue 1: ZetaSQLType is not updated — declared output types for ROUND/CEIL/FLOOR/TRUNC/SIGN on TINYINT/SMALLINT may not match the actual runtime values
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:490 - Why it matters: - Root cause: this PR changes the runtime return types of the functions (
round(...)now returnsBytefor TINYINT input via the newcase "BYTE":at NumericFunction.java:259, andsign(...)now accepts Byte/Short but always returnsIntegerat line 490), yetZetaSQLType.java— which declares the outputSeaTunnelDataTypeof each function — is untouched. The related fix #11712 for BIGINT/DECIMAL had to changeZetaSQLType.javaalongsideNumericFunction.javafor exactly this reason. - Impact: if the declared output type for these functions over TINYINT/SMALLINT arguments does not match the
Byte/Short/Integervalues now produced at runtime, downstream schema-driven consumers (sink converters, subsequent transforms) can fail or corrupt data. - Suggested action: align
ZetaSQLType#getFunctionTypefor ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC with BYTE/SHORT arguments, and add a row-type assertion to the tests so declared and runtime types stay in sync. - Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:489 if (v1 instanceof Byte || v1 instanceof Short || v1 instanceof Integer) {;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:490 return Integer.signum(v1.intValue());;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue(); - Suggested fix:
sign()now accepts Byte/Short inputs but still returnsInteger, andround()now returnsBytefor TINYINT input — yetZetaSQLType.java(which declares the SQL output types) is not touched in this PR. #11712 had to updateZetaSQLTypetogether withNumericFunctionfor the same class of fix. Please alignZetaSQLType#getFunctionTypefor ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC with BYTE/SHORT args so the declared output type matches the actual runtime value, and add a row-type assertion inSQLNumericFunctionsTestto lock this in. - Severity: Medium
Issue 2: round() helper now throws for previously pass-through Number types — a silent behavior break that also affects CEIL/FLOOR/TRUNC/TRUNCATE
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316 - Why it matters: - Root cause: the new
default:branch in the sharedround(Number, Number, RoundingMode)helper (NumericFunction.java:311-316) turns what used to be a silent pass-through into a hardTransformException. This helper backs ROUND, CEIL, FLOOR, TRUNC and TRUNCATE, so all five functions change behavior at once. - Impact: any existing Zeta SQL transform pipeline that fed an unusual
Numberimplementation (e.g.BigIntegercoming from a connector's custom type mapping) through these functions previously received the input back unchanged; after upgrade the same pipeline fails at runtime. Additionally, the exception message hardcodesZetaSQLFunction.ROUND, so a failure inCEIL(x)is reported as a ROUND error, misleading users during triage. - Suggested action: keep the fail-fast behavior but pass the actual function name into the helper for the error message, and call out the behavior change in the release notes.
- Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:315 "Unsupported arg type %s of function %s",;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316 v1.getClass().getName(), ZetaSQLFunction.ROUND));;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column)); - Suggested fix: Two points here:
- This
default:branch is a behavior change — types likeBigIntegerused to pass through ROUND/CEIL/FLOOR/TRUNC unchanged and will now fail the job. I agree fail-fast is correct, but please mention it in the release notes so users upgrading are not surprised. - This helper is shared by CEIL/FLOOR/TRUNC/TRUNCATE, yet the message hard-codes
ZetaSQLFunction.ROUND. A user callingCEIL(x)will get an error blaming ROUND. Please pass the actual function name into the helper and use it in the message.
- Severity: Medium
Issue 3: Runtime return types changed to Byte/Short without touching ZetaSQLType — possible mismatch between declared output schema and produced values
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:39 - Why it matters: - Root cause:
absnow returns(byte)/(short)(NumericFunction.java:39, 45) and the ROUND/CEIL/FLOOR/TRUNC family now returnscolumn.byteValue()for TINYINT input (NumericFunction.java:329), but this PR does not modifyZetaSQLType, which is where SQLTransform derives the output column type for these functions (PR #11712 had to changeZetaSQLTypefor the analogous BIGINT/DECIMAL fix). - Impact: if
ZetaSQLType.getFunctionTypestill mapsABS/ROUNDover TINYINT/SMALLINT args to a wider type such as INT, the output schema will declare INT while rows actually carryByte/Shortvalues, which can break sink converters at runtime. - Suggested action: verify and align the ZetaSQLType mapping for these functions, and extend
testSmallIntegerNumericFunctionsto assert the transform's produced row type in addition to the values. - Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:45 return (short) Math.abs(arg.shortValue());;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue(); - Suggested fix:
abs/roundnow produceByte/Shortat runtime, but the PR doesn't touchZetaSQLType, which drives the declared output column type for these functions (compare #11712, which had to updateZetaSQLTypealongsideNumericFunction). Please confirmZetaSQLType.getFunctionTypemaps ABS/ROUND/CEIL/FLOOR/TRUNC over TINYINT/SMALLINT to the matching type; otherwise the output schema will say INT while rows carryByte, breaking sink converters at runtime. It would also help iftestSmallIntegerNumericFunctionsasserted the transform's produced row type, not only the values. - Severity: Medium
Issue 4: No documentation update for the new TINYINT/SMALLINT support and new failure modes in docs/transform-v2/sql-functions.md
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:37 - Why it matters: - Root cause: the PR changes user-visible SQL function behavior — ABS now throws on
Byte.MIN_VALUE/Short.MIN_VALUE(NumericFunction.java:35-43 plus the newcannotRepresentAbsoluteValuehelper at 341-347), ROUND/CEIL/FLOOR/TRUNC now actually round TINYINT and fail on overflow, and unsupported Number types now error — but no file underdocs/is changed. - Impact: users reading the SQL functions reference (
docs/transform-v2/sql-functions.mdand its zh counterpart) have no way to know these functions now support TINYINT/SMALLINT or that valid inputs likeABS(-128)on TINYINT will now fail the job. - Suggested action: update the ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC entries in both the English and Chinese SQL functions docs to document the new small-integer support and the explicit error conditions.
- Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:37 throw cannotRepresentAbsoluteValue(arg, "TINYINT");;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:344 "Function %s cannot represent the absolute value of %s for %s", - Suggested fix: This introduces a new user-visible failure mode:
ABSon a TINYINT/SMALLINT column now fails the job for the minimum value instead of returning a result. Please update the ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC entries indocs/transform-v2/sql-functions.md(English and Chinese) to document the new TINYINT/SMALLINT support and these explicit error conditions — right now the PR ships no docs change at all. - Severity: Medium
Issue 5: New default-throw in the shared rounding helper turns previously-silent pass-through into a runtime failure for ROUND/CEIL/FLOOR/TRUNC/TRUNCATE
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:311 - Why it matters: - Root cause: the added
default:branch (NumericFunction.java:311-316) makes the sharedround(Number, Number, RoundingMode)helper throwTransformException(UNSUPPORTED_OPERATION)for anyNumbersubtype not in the switch, where previously the helper fell through and returnedv1unchanged. - Impact: this is the right hardening for #11935, but it is a behavior change on upgrade — any pipeline feeding a non-standard
Number(e.g.,BigInteger) through ROUND/CEIL/FLOOR/TRUNC/TRUNCATE will now fail at runtime instead of silently passing the value through. - Suggested action: document the change in the transform SQL-functions docs and release notes so upgrading users can attribute the new exception correctly.
- Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:312 throw new TransformException(;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:315 "Unsupported arg type %s of function %s",;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316 v1.getClass().getName(), ZetaSQLFunction.ROUND)); - Suggested fix: Failing fast here is the right call, but note this flips behavior from "return the input unchanged" to "fail the job" for any Number subtype outside the switch (e.g., BigInteger), and it applies to CEIL/FLOOR/TRUNC/TRUNCATE too since they share this helper. Please call this out in the transform SQL-functions docs / release notes so upgrading users can attribute the new exception correctly.
- Severity: Medium
Issue 6: Asymmetric overflow handling: TINYINT rounding overflow throws, but SMALLINT rounding still silently wraps via shortValue()
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324 - Why it matters: - Root cause: the new
case "BYTE"inconvertTo(NumericFunction.java:323-329) adds an explicit range guard before narrowing, but the adjacentcase "SHORT"path that this same PR routes small integers through (thecase "BYTE": case "INTEGER": case "SHORT": case "LONG":fall-through added at NumericFunction.java:259) still returnscolumn.shortValue()with no range check. - Impact:
ROUND(smallint_col, -1)on a value like(short) 32767produces32770, whichshortValue()silently wraps to a negative value — the exact silent-corruption pattern this PR fixes for TINYINT remains for SMALLINT. - Suggested action: add the equivalent
Short.MIN_VALUE/Short.MAX_VALUEguard forSHORT(and considerINTEGER, which wraps the same way viaintValue()), with a mirrored overflow test. - Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324 if (column.longValue() < Byte.MIN_VALUE || column.longValue() > Byte.MAX_VALUE) {;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column));;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:259 case "BYTE": - Suggested fix: This range guard is a good addition for TINYINT, but the
SHORTcase right below still does an uncheckedcolumn.shortValue(), soROUND(smallint_col, -1)on32767will silently wrap to a negative value — the same silent-corruption pattern this PR fixes for TINYINT. Since the PR is titled "small integer" support, please add the equivalentShort.MIN_VALUE/Short.MAX_VALUEguard forSHORT(and ideallyINTEGER, which has the same wrap viaintValue()), plus a mirrored overflow test. - Severity: Medium
Issue 7: Overflow guard in convertTo() is added only for BYTE; SHORT and INTEGER results from the same rounding path still wrap silently
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 - Why it matters: - Root cause: this PR adds an explicit range check before narrowing to byte in
convertTo(), but the sibling branches in the same switch (case "INTEGER": return column.intValue();andcase "SHORT": return column.shortValue();) still perform unchecked narrowing on the roundedBigDecimal. - Impact: the exact bug class this PR fixes for TINYINT remains for SMALLINT/INT on Zeta. For example
ROUND(smallint_col, -1)with input32767rounds to32770, andcolumn.shortValue()silently wraps it to a negative value instead of failing. - Suggested action: apply the same bounds check and
TransformExceptionto the SHORT and INTEGER cases so all fixed-width integer types behave consistently. - Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324 if (column.longValue() < Byte.MIN_VALUE || column.longValue() > Byte.MAX_VALUE) {;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue(); - Suggested fix: Nice to see the explicit range check for TINYINT, but the SHORT and INTEGER branches right below still narrow with
column.shortValue()/column.intValue()unchecked.ROUND(CAST(32767 AS SMALLINT), -1)rounds to 32770 and silently wraps to a negative value — the exact silent-corruption bug this PR fixes for BYTE. Please add the same bounds check (and TransformException) for the SHORT and INTEGER cases so all fixed-width integers behave consistently. - Severity: Medium
Issue 8: Value-overflow conditions are reported with the deprecated UNSUPPORTED_OPERATION error code, which misclassifies data-range errors
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:326 - Why it matters: - Root cause: both the new ABS overflow helper and the TINYINT rounding-overflow guard use
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION, an error code meant for unsupported operations/types, to signal an out-of-range data value. - Impact: operators triaging Zeta job failures will see an 'unsupported operation' code for what is actually a data-quality/overflow condition (e.g., a legitimate TINYINT value of -128 hitting ABS), which makes log-based alerting and troubleshooting misleading; the code is also already marked deprecated.
- Suggested action: use a data/overflow-oriented error code from the current CommonError set for both
cannotRepresentAbsoluteValueand the rounding-overflow guard. - Evidence:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:326 CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,;seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column)); - Suggested fix: This is an out-of-range data condition, not an unsupported operation — reporting it as
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION(a deprecated code, too) will mislead users triaging failures. Consider using a data/overflow-oriented error code from the current CommonError set here and incannotRepresentAbsoluteValue, and documenting that ABS(-128) on TINYINT now fails explicitly since -128 is a valid input value. - Severity: Low
Review conclusion
Conclusion: final approval remains pending on the previous comments
2. Remaining follow-ups
- Issue 1: ZetaSQLType is not updated — declared output types for ROUND/CEIL/FLOOR/TRUNC/SIGN on TINYINT/SMALLINT may not match the actual runtime values
- Issue 2: round() helper now throws for previously pass-through Number types — a silent behavior break that also affects CEIL/FLOOR/TRUNC/TRUNCATE
- Issue 3: Runtime return types changed to Byte/Short without touching ZetaSQLType — possible mismatch between declared output schema and produced values
- Issue 4: No documentation update for the new TINYINT/SMALLINT support and new failure modes in docs/transform-v2/sql-functions.md
- Issue 5: New default-throw in the shared rounding helper turns previously-silent pass-through into a runtime failure for ROUND/CEIL/FLOOR/TRUNC/TRUNCATE
- Issue 6: Asymmetric overflow handling: TINYINT rounding overflow throws, but SMALLINT rounding still silently wraps via shortValue()
- Issue 7: Overflow guard in convertTo() is added only for BYTE; SHORT and INTEGER results from the same rounding path still wrap silently
- Issue 8: Value-overflow conditions are reported with the deprecated UNSUPPORTED_OPERATION error code, which misclassifies data-range errors
Thanks for the updates so far. Happy to discuss the remaining points.
|
Thanks for the deep independent pass, @SEZ9 — really useful to have a second set of eyes on this file. Went through all eight points against the current head ( Corroborates my Issue 2 (SMALLINT overflow-wrap unguarded) — your Issues 6 and 7. Same finding, independently reached: the new Corroborates my Issue 3 (missing I'd push back on Issues 1 and 3 (ZetaSQLType mismatch), with evidence. I checked
So I don't think I'd also push back on Issue 4 (missing docs), with a path correction. The file doesn't exist at Issue 8 (deprecated error code) — fair, taking it as a reasonable low-severity addition. No disagreement there. One thing your review doesn't touch on that I'd like your read on: the bigger-picture Issue 1 from my own review — this PR duplicates the scope of the already twice-approved |
DanielLeens
left a comment
There was a problem hiding this comment.
What Problem Does This PR Solve?
This PR originally aimed to fix issue #11935: Zeta SQL numeric functions (ABS, ROUND, CEIL, FLOOR, TRUNC, TRUNCATE, SIGN) mishandled TINYINT/SMALLINT (Byte/Short) columns — ABS/SIGN rejected them outright, and ROUND/CEIL/FLOOR/TRUNC silently returned TINYINT values unrounded.
Important update since the last review round: between my previous review (commit 034a3f47) and the current head (a2512938), a competing PR that fixed the exact same issue — #11937, "Handle TINYINT and SMALLINT in Zeta SQL numeric functions" — was merged into dev and closed #11935 (2026-09-01, ~07:29 UTC). The author of this PR then pushed a merge commit here, a2512938 ("Sync numeric functions with dev"), which merges the latest dev into this branch. I verified by diffing this PR's actual head against that merge-base that this had a real, material effect: NumericFunction.java and ZetaSQLType.java in this PR are now byte-for-byte identical to dev. The author's own original implementation was superseded by dev's (via #11937) during that merge, and only test-file changes remain.
So, concretely, the official diff of this PR (gh pr diff 12007) today is exactly two files, 57 net inserted lines, both test-only:
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.javaseatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java
There is no longer any production-code change in this PR. Example of the actual current diff (not a fix, just an added unit assertion):
// NumericFunctionTest.java, inside the existing testAbsForDifferentNumberTypes()
Assertions.assertEquals(
(byte) 10, NumericFunction.abs(Collections.singletonList((byte) -10)));1. Code Change Review
1.1 Core Logic Analysis
Since there is no production-code diff, "core logic" here means: do the two remaining test files still add value, and are their assertions correct against the actual (now dev-identical) runtime behavior?
I traced the runtime path independently of the two prior reviews' conclusions, against the current source:
SQLTransformparses the SQL, resolves each function viaZetaSQLFunction, and asksZetaSQLType#getFunctionType(seatunnel-transforms-v2/.../zeta/ZetaSQLType.java:458-471) for the declared output type. ForABS/ROUND/CEIL/CEILING/FLOOR/TRUNC/TRUNCATE, this returnsgetExpressionType(function.getParameters().getExpressions().get(0))— i.e. the type of the first argument, so aTINYINT(BYTE) argument declares aBYTEoutput.SIGNis hardcoded atZetaSQLType.java:376toBasicType.INT_TYPE.- At execution time,
NumericFunction.abs()/round()/sign()(.../zeta/functions/NumericFunction.java) dispatch on the runtimeNumbertype.round()'s shared switch (line ~265) now hascase "BYTE": case "INTEGER": case "SHORT": case "LONG":sharing one code path, narrows viaconvertTo(), which now calls a sharedcheckIntegralRange(value, min, max, sqlType, function)helper (line ~356) uniformly forBYTE/INTEGER/SHORT/LONG— this is #11937'scheckIntegralRangehelper, already merged. - I independently re-verified (not just trusted the prior review's rebuttal) that
sign()/abs()output types line up withZetaSQLType's declarations for theByte/Shortbranches:abs((byte)-10)returns aByte, matching the declaredBYTEoutput type;sign()always returns anInteger, matching the hardcodedINT_TYPE. No mismatch found. - This confirms the normal user path (a
SELECT ROUND(tiny_col, -1) ...query against aTINYINTcolumn) does reach this dispatch chain end-to-end, not just a rarely-hit branch.
Given that, the two remaining test files:
NumericFunctionTest.javaadditions (lines ~95-97, 109-112, 205-208, 211-216, 290, 307 in the current PR branch) add unit assertions forByte/Shortabs()/sign(),MIN_VALUEoverflow,Byteround()/ceil()/floor()/trunc(),Byte.MAX_VALUEround-overflow, an unsupported-BigIntegercase, and aBigDecimal("1E-400")sign()case. I checked every one of these againstdev's own test suite (added by #11937) and every single assertion here duplicates an assertion already present indev— same inputs, same expected outputs — just organized inside older, more generically-named test methods instead of #11937's new, purpose-named ones (testAbsAndSignAcceptTinyIntAndSmallInt,testRoundingFamilyHandlesTinyInt,testTinyIntRoundingRejectsResultsThatDoNotFit,testRoundingRejectsUnhandledNumericTypes,testSignIsExactForDecimalsBelowDoubleRange, all already indev). All values are correct (verified against the real, mergedcheckIntegralRange-based logic), just redundant.SQLNumericFunctionsTest.java's newtestSmallIntegerNumericFunctions()(line 74) is the one genuinely useful addition: it is, as of right now, the only test anywhere (includingdev's own suite) that exercisesCEIL/FLOOR/TRUNCon aTINYINTcolumn through the fullSQLTransformpipeline (SQL parsing →ZetaSQLTypedispatch →NumericFunctionexecution → row value). I confirmed this by greppingdev'sSQLNumericFunctionsTest.java: its owntestTinyIntAndSmallIntFlowThroughNumericFunctions()only exercisesROUND/ABS/SIGNat the SQL level, andCEIL/FLOORelsewhere in that file are only exercised againstDOUBLEcolumns. I hand-checked the new test's expected values against-44with scale-1:ABS=44,SIGN(-12)=-1,ROUND=-40,CEIL=-40,FLOOR=-50,TRUNC=-40— all correct for standard half-up rounding / ceiling-toward-+inf / floor-toward-−inf / truncate-toward-zero semantics.
1.2 Compatibility Impact
None from this PR's current diff — it is test-only. The behavior changes originally described in this PR's own description (TINYINT rounding, ABS/SIGN acceptance, BigDecimal sign fix, default-throw for unhandled types) are real, but they shipped via #11937, which is already merged, already documented in docs/en(zh)/introduction/concepts/incompatible-changes.md, and out of scope for re-litigating here since this PR's diff no longer contains them.
One process-level compatibility concern specific to this PR: its title and description are now stale and materially misleading relative to its actual diff. The PR body (fetched from GitHub) still reads "Adds TINYINT and SMALLINT support to Zeta SQL numeric functions" with a bulleted list of behavior changes and "Closes #11935" — but #11935 is already closed (by #11937), and none of the described behavior changes are in this PR's diff anymore. Since this project squash-merges with the PR title becoming the permanent commit message (per this repo's own commit convention: [Type][Module] Description), merging as-is would write a misleading entry into git log claiming this PR delivered functionality it did not deliver — the real fix's authorship and history belong to #11937.
1.3 Performance / Side-Effect Analysis
None. Test-only diff; no new allocations, threads, locks, or I/O in the production path (which is unchanged from dev).
1.4 Error Handling and Logging
No new error handling in this PR's diff. For completeness, I re-checked (independently, not trusting the earlier reviews) whether SEZ9's Issue 8 from the previous round — that overflow conditions are reported via the deprecated CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION rather than a data/overflow-specific code — is still true in the merged checkIntegralRange helper (NumericFunction.java, checkIntegralRange). It is still true, but it's now purely a dev/#11937 characteristic, not something introduced or fixable by this PR, since this PR no longer touches that file.
2. Code Quality Assessment
2.1 Coding Standards
Clean, minimal test additions, consistent with the surrounding code. One note carried over from checking the file's own history rather than a new-to-this-PR problem: the new assertions use fully-qualified org.apache.seatunnel.transform.exception.TransformException.class and java.math.BigInteger inline instead of using the file's own existing import org.apache.seatunnel.transform.exception.TransformException;. I checked the merge-base version of this file and confirmed this FQN-inline pattern already existed throughout the file before this PR, so it is a pre-existing file convention, not a new problem introduced here — not counted as a blocking issue, just noted for completeness per this project's "explain why, don't just restate" comment standard (no comment issue found; the added assertions are self-explanatory one-liners consistent with the surrounding style).
2.2 Test Coverage and Test Stability
Stability rating: Stable. Every new assertion (in both files) is a deterministic, pure-function or in-memory SQLTransform evaluation: no Thread.sleep, no timing dependencies, no shared mutable state across tests, no floating-point comparison without a delta (the one BigDecimal case uses assertEquals on exact decimal semantics, which is appropriate). No flakiness risk.
Coverage: as detailed in 1.1, most of the NumericFunctionTest.java additions duplicate coverage dev already has via #11937 — they don't hurt, but they don't help either, and create a second, disconnected place that would need updating if this behavior ever changes again. The SQLNumericFunctionsTest.java addition is a real, narrow coverage gap-filler (SQL-level CEIL/FLOOR/TRUNC on TINYINT) that is worth keeping.
2.3 Documentation Updates
Not applicable to this PR's current diff (test-only, no user-visible behavior change). The user-visible documentation for the actual TINYINT/SMALLINT support (in docs/en(zh)/transforms/sql-functions.md and incompatible-changes.md) was already handled by #11937.
3. Architectural Soundness
3.1 Elegance of the Solution
The author's decision to merge dev and let it override their own now-superseded implementation, rather than fighting for a duplicate fix, is the right call and matches the outcome my own previous review (and SEZ9's) recommended — coordinate rather than ship two competing fixes for the same file. What's left is a small, targeted test-coverage supplement, which is the right shape for a follow-up, but it is currently packaged under a PR title/description that no longer matches its contents (see Issue 1).
3.2 Maintainability
The duplicate assertions in NumericFunctionTest.java (Issue 2 below) are a minor, low-risk maintainability tax: two sets of assertions for the same TINYINT/SMALLINT values, organized differently, that a future change would need to keep in sync by hand.
3.3 Extensibility
No concerns; nothing here changes any shared code path.
3.4 Historical-Version Compatibility
No concerns from this PR's current diff. The compatibility-relevant work (round/abs/sign behavior changes, incompatible-changes.md entries) already shipped and is already reviewed/merged via #11937.
4. Issue Summary
| # | Issue | Location | Severity |
|---|---|---|---|
| 1 | PR title/description are stale and materially misleading relative to the actual (test-only) diff; squash-merging as-is would write an inaccurate permanent commit message claiming this PR delivered TINYINT/SMALLINT support that actually shipped via #11937 | PR title & description (GitHub metadata) | Medium |
| 2 | NumericFunctionTest.java additions duplicate assertions already present in dev's own test suite (merged via #11937): same TINYINT/SMALLINT abs/sign/round/overflow/BigInteger/BigDecimal-1E-400 cases, just under older/more generic test method names |
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java (new lines ~95-97, 109-112, 205-208, 211-216, 290, 307) |
Low |
| 3 | Two SQL-level tests now cover overlapping TINYINT/SMALLINT ground with different names/scopes: dev's own testTinyIntAndSmallIntFlowThroughNumericFunctions and this PR's new testSmallIntegerNumericFunctions — worth consolidating into one method for future readability |
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java:74 vs dev's testTinyIntAndSmallIntFlowThroughNumericFunctions |
Low |
5. Merge Recommendation
Conclusion: Ready to merge after fixes
1. Blockers — must be fixed
- Issue 1: Update the PR title and description before merge. Since #11935 is already closed by the merged #11937, and this PR's diff is now test-only, the title/description should no longer claim to add TINYINT/SMALLINT support or "Closes #11935" — please retitle along the lines of
[Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns(or similar) and rewrite the body to say this supplements the already-merged #11937 with one additional end-to-end SQL-level test. This matters concretely because this repo squash-merges using the PR title as the permanent commit message.
2. Recommended fixes — non-blocking
- Issue 2: Consider dropping the duplicate assertions added to
NumericFunctionTest.java— they add no coverage beyond whatdevalready has via #11937 and just create a second place to maintain the same values. - Issue 3: Consider folding the new
testSmallIntegerNumericFunctionsintodev's existingtestTinyIntAndSmallIntFlowThroughNumericFunctions(or clearly differentiating the two by name/comment) rather than leaving two similarly-scoped SQL-level tests for the same feature area.
Overall assessment: This PR started as a duplicate fix for an issue that a competing, already-approved PR (#11937) also targeted — my previous review flagged that duplication as the primary blocker. That risk has now fully materialized and resolved itself the right way: #11937 merged first, and the author's own merge commit here (a2512938, "Sync numeric functions with dev") correctly let dev's implementation win, leaving NumericFunction.java and ZetaSQLType.java byte-for-byte identical to dev. What remains is low-risk, test-only, and mostly redundant, but it does contain one small piece of genuine value: testSmallIntegerNumericFunctions is currently the only test anywhere that proves CEIL/FLOOR/TRUNC resolve correctly through the full SQL-parsing-to-execution pipeline for TINYINT columns, which is worth keeping. I'd merge this readily once the title/description are corrected to reflect what the PR actually does today — thank you for the good-faith sync with dev rather than pushing a duplicate implementation, @zhangshenghang.
The previous Build workflow run (created 2026-09-01) can no longer be re-run because GitHub rejects re-runs of runs created over a month ago. Its only failing job was all-connectors-it-4 (8, ubuntu-latest), where AzureCosmosDBSourceIT timed out talking to the Cosmos DB emulator (CosmosException 408/10002, ReadTimeoutException) - unrelated to the test-only changes in this PR. Re-trigger the build with an empty commit. Co-Authored-By: Claude Code <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
The branch was 400 commits behind dev and missing two upstream CI fixes: - apache#12287 and follow-ups: Docker Hub minio/minio no longer serves anonymous pulls, S3-backed e2e tests now use a digest-pinned ghcr.io mirror - apache#12830: self-host the DeepWiki badge image Both caused failures unrelated to this PR's test-only changes (all transform-v2 jobs passed on the old head). PR test additions unchanged; verified with JDK 17: NumericFunctionTest + SQLNumericFunctionsTest green (46 tests), spotless:check clean. Co-Authored-By: Claude Code <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
DanielLeens
left a comment
There was a problem hiding this comment.
Review conclusion
Reviewed commit: 612d91b
No source-level blocking finding found in the complete test-only diff. The new SQL-level test exercises the public transform path for BYTE/SHORT inputs, while the function-level assertions cover type preservation, overflow rejection, negative-scale rounding, and tiny non-zero BigDecimal sign handling. This is the correct regression boundary: it checks both parser/type propagation and the underlying numeric functions without changing production behavior.
Compatibility: no runtime, API, configuration, or serialization change.
Validation performed: fetched the current ref; inspected both changed test classes and the covered NumericFunction/SQL transform call paths. No local build/test was run because the review scope is test coverage only.
CI gate: Build timed out, so final merge remains blocked pending a successful rerun.
Conclusion
No source-level blocking finding. Final merge gate: green CI required.
|
Quick follow-up on the CI fact I cited in my previous review: the My earlier review found no source-level blocking issue in this test-only diff, and CI was the only remaining gate. With the check now green, I have nothing further on my side, so I am updating my conclusion to approve. Thanks again for keeping this in sync with Note: I only have read-level permissions on this repository, so GitHub may keep showing earlier review states; a committer with write access can complete the final merge step. Conclusion: Ready to merge |
DanielLeens
left a comment
There was a problem hiding this comment.
Re-checked current head 612d91b590b7, which is unchanged since my last review. In that review I found no source-level blocker, and the only remaining item was CI (my review recorded that Build had timed out). CI was previously the only remaining blocker, and it is now passing: the fork Build run 39086475909 completed with success for exactly this head SHA, and the apache-side Build check reports success as well. So my conclusion changes to approve. This is a test-only change with no runtime, API, configuration or serialization impact. Thanks again for the focused SQL-level coverage, @zhangshenghang!
Note: my reviewer account is read-only on this repository, so a maintainer with write access still needs to do the final merge. The branch being behind dev is merge metadata only and does not by itself need a source change.
davidzollo
left a comment
There was a problem hiding this comment.
基本信息
- 标题:[Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns
- 中文释义:为已合入的 #11937(TINYINT/SMALLINT 数值函数支持)补充 SQL 层回归测试和单测断言
- 作者:zhangshenghang
- 目标分支:dev
- 变更量:+57 / -0,2 个文件
- 状态:OPEN,可合并
- Review 报告时间:2026-10-21 09:20:53 EDT (UTC-04:00)
- 本地分支:pr-12007(head
612d91b590b7) - PR 链接:#12007
PR 解决了什么问题(小白示例)
- 用户痛点:#11937 让 ABS、SIGN、ROUND、CEIL、FLOOR、TRUNC 支持 TINYINT/SMALLINT 列,但缺少一条从 SQL 解析到执行的完整回归测试;以后谁改坏了类型分发,单测可能仍是绿的。
- 修复方式:在
SQLNumericFunctionsTest增加testSmallIntegerNumericFunctions,用真实 SQL 对(byte) -44和(short) -12跑六个函数并断言返回类型与值;在NumericFunctionTest增加 Byte/Short 的 abs/sign/round/ceil/floor/trunc 断言、Byte.MIN_VALUE/Short.MIN_VALUE的溢出异常、BigInteger不支持异常以及1E-400的精确符号判断。 - 一句话:纯测试补充,没有生产代码变化。
一、代码变更审查
1.1 核心逻辑分析
变更内容精确描述
SQLNumericFunctionsTest.java:+28,新增一个@Test。NumericFunctionTest.java:+29,在三个现有测试方法中增加断言。- 作者说明同步 dev 后
NumericFunction.java与ZetaSQLType.java与 #11937 合入版本逐字节相同;git diff --stat upstream/dev...pr-12007确认本 PR 只含两个测试文件。
关键发现
- 无生产代码变化,正常路径不受影响。
- 新断言都具备失败能力:例如
ROUND((byte) 44, -1)期望(byte) 40,若类型分发回退到 int 就会因返回类型不同而失败;Byte.MIN_VALUE的 abs 溢出期望抛TransformException。 - 现有断言未被删除或放宽,只有新增。
逻辑正确性深度分析
- SQL 层测试通过
runSql构造SeaTunnelRowType {BYTE_TYPE, SHORT_TYPE},断言输出字段类型为Byte/Integer(SIGN 返回 int),与 #11937 的实现一致。 1E-400的BigDecimal符号测试验证的是signum()而非 double 转换(double 下会是 0),有意义。
1.2 兼容性影响
完全兼容,测试代码。
1.3 性能 / 副作用分析
无。
1.4 错误处理与日志
不适用。
1.5 引擎改动专项检查
不适用。
二、代码质量评估
2.1 代码规范
测试中两处以全限定名引用 org.apache.seatunnel.transform.exception.TransformException.class 和 new java.math.BigInteger("1"),同文件已有 import 的情况下可改为简名;属于风格细节,非阻塞。
2.2 测试覆盖
- 单测:覆盖 Byte/Short 的六个函数、溢出边界、不支持类型、精确符号。
- SQL 层:覆盖解析到执行的完整链路。
- E2E:不需要;transform 函数的 SQL 层测试已是最接近用户路径的层级。
本地验证结果
git fetch upstream pull/12007/head:pr-12007:通过;head612d91b590b7。git diff --stat upstream/dev...pr-12007:通过;2 个测试文件,+57 / -0。git diff upstream/dev...pr-12007:通过;逐行阅读全部新增断言,确认无删除或放宽。gh pr checks 12007:通过;BuildSUCCESS。- 编译 / 测试:未执行。原因:Review PR 默认不做本地编译;当前 head 的 GitHub CI 已运行这两个测试类并通过。
2.3 文档更新
不需要。
三、架构合理性
3.1 解决方案的优雅性
最佳改动位置评估
- 当前改动位置:
seatunnel-transforms-v2的两个现有测试类。 - 根因位置:根因不适用(测试补充);职责归属是把 SQL 层回归测试放在
SQLNumericFunctionsTest,把函数级断言放在NumericFunctionTest,与现有分层一致。 - 是否为最佳改动:是。
- 全局最佳改动位置:同当前位置。
- Merge 影响:不阻塞。
3.2 可维护性
在现有测试方法内追加断言,符合项目“扩展现有测试类”的惯例。
3.3 扩展性
不涉及。
3.4 历史版本兼容性
不涉及。
四、问题汇总
全量问题穷尽自检
- PR diff / changed files:2 个文件已逐行审查完。
- 关键调用链:测试到
NumericFunction/ZetaSQLFunction的调用已核对;无生产代码变化。 - 根因 / 当前改动位置 / 最佳改动位置 / 方案取舍:已判断(根因不适用)。
- 兼容性 / 升级路径 / 协议或配置契约:不涉及。
- 测试分层 / 文档 / 示例 / 默认配置:已核对。
- Whale 协同仓库:不涉及。
- CI / Review / 冲突 gate:
BuildSUCCESS,DanielLeens 已 APPROVE,无冲突。 - 无法审查范围:无。
问题清单:
- 测试中以全限定名引用
TransformException与BigInteger(NumericFunctionTest.java新增断言处),可改为 import 简名。严重程度:低。是否阻塞:否。
五、是否可以 Merge 的结论
结论:可以 merge
阻塞项(必须修复):无。
建议修复(非阻塞):问题 1,纯风格,可在后续任意 PR 顺手处理。
整体评价:具备失败能力的测试补充,不触及生产代码,CI 已绿。
What does this PR do?
Supplements the already-merged #11937 (which delivered TINYINT/SMALLINT support for Zeta SQL numeric functions) with test-only additions:
testSmallIntegerNumericFunctions) proving that ABS, SIGN, ROUND, CEIL, FLOOR, and TRUNC resolve and execute correctly for TINYINT/SMALLINT columns through the full SQL parsing-to-execution pipeline.NumericFunctionTest.No production code changes: after syncing with dev,
NumericFunction.javaandZetaSQLType.javaare byte-for-byte identical to the implementation already merged via #11937.Tests
Validated with: